<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>pprof 支持 | Orange框架</title>
    <meta name="generator" content="VuePress 1.9.10">
    <link rel="icon" href="/orange_doc/images/logo.jpg">
    <script>
            var _hmt = _hmt || [];
			(function() {
			  var hm = document.createElement("script");
			  hm.src = "https://hm.baidu.com/hm.js?a0c745d027acbd6848330c087669dc94";
			  var s = document.getElementsByTagName("script")[0]; 
			  s.parentNode.insertBefore(hm, s);
			})();
			</script>
    <meta name="description" content="orange框架,简洁高效的web开发框架, Golang用户极速开发体验。">
    <meta description="orange框架,简洁高效的web开发框架, Golang用户极速开发体验。">
    
    <link rel="preload" href="/orange_doc/assets/css/0.styles.4198b232.css" as="style"><link rel="preload" href="/orange_doc/assets/js/app.e323b7be.js" as="script"><link rel="preload" href="/orange_doc/assets/js/2.8ffd84cf.js" as="script"><link rel="preload" href="/orange_doc/assets/js/1.d3b0779f.js" as="script"><link rel="preload" href="/orange_doc/assets/js/30.30aeda31.js" as="script"><link rel="prefetch" href="/orange_doc/assets/js/10.d11338bf.js"><link rel="prefetch" href="/orange_doc/assets/js/11.03586221.js"><link rel="prefetch" href="/orange_doc/assets/js/12.8f3f5530.js"><link rel="prefetch" href="/orange_doc/assets/js/13.6489b7e0.js"><link rel="prefetch" href="/orange_doc/assets/js/14.3df437f3.js"><link rel="prefetch" href="/orange_doc/assets/js/15.be27f4ba.js"><link rel="prefetch" href="/orange_doc/assets/js/16.ea700694.js"><link rel="prefetch" href="/orange_doc/assets/js/17.a85dc572.js"><link rel="prefetch" href="/orange_doc/assets/js/18.359b700c.js"><link rel="prefetch" href="/orange_doc/assets/js/19.1ed550c9.js"><link rel="prefetch" href="/orange_doc/assets/js/20.067f2700.js"><link rel="prefetch" href="/orange_doc/assets/js/21.c8159272.js"><link rel="prefetch" href="/orange_doc/assets/js/22.3927f69e.js"><link rel="prefetch" href="/orange_doc/assets/js/23.64866326.js"><link rel="prefetch" href="/orange_doc/assets/js/24.405e9861.js"><link rel="prefetch" href="/orange_doc/assets/js/25.3f633c9f.js"><link rel="prefetch" href="/orange_doc/assets/js/26.26fdfa66.js"><link rel="prefetch" href="/orange_doc/assets/js/27.91b3d914.js"><link rel="prefetch" href="/orange_doc/assets/js/28.cd43e5e2.js"><link rel="prefetch" href="/orange_doc/assets/js/29.b587e0e0.js"><link rel="prefetch" href="/orange_doc/assets/js/3.36478a47.js"><link rel="prefetch" href="/orange_doc/assets/js/31.e61a62f2.js"><link rel="prefetch" href="/orange_doc/assets/js/32.124d2d7c.js"><link rel="prefetch" href="/orange_doc/assets/js/33.24b9dcd3.js"><link rel="prefetch" href="/orange_doc/assets/js/34.a5c00fc8.js"><link rel="prefetch" href="/orange_doc/assets/js/35.a7e238db.js"><link rel="prefetch" href="/orange_doc/assets/js/36.42c5fbe4.js"><link rel="prefetch" href="/orange_doc/assets/js/37.e014361d.js"><link rel="prefetch" href="/orange_doc/assets/js/38.5c677c29.js"><link rel="prefetch" href="/orange_doc/assets/js/39.d9324044.js"><link rel="prefetch" href="/orange_doc/assets/js/4.7e9344c8.js"><link rel="prefetch" href="/orange_doc/assets/js/40.b4486e63.js"><link rel="prefetch" href="/orange_doc/assets/js/41.daf98a13.js"><link rel="prefetch" href="/orange_doc/assets/js/42.4126b76f.js"><link rel="prefetch" href="/orange_doc/assets/js/43.d232e117.js"><link rel="prefetch" href="/orange_doc/assets/js/44.324be1ea.js"><link rel="prefetch" href="/orange_doc/assets/js/45.6d5645a4.js"><link rel="prefetch" href="/orange_doc/assets/js/46.8127c460.js"><link rel="prefetch" href="/orange_doc/assets/js/47.6a6a20c1.js"><link rel="prefetch" href="/orange_doc/assets/js/48.538157de.js"><link rel="prefetch" href="/orange_doc/assets/js/49.ab9e2921.js"><link rel="prefetch" href="/orange_doc/assets/js/5.45a5aec7.js"><link rel="prefetch" href="/orange_doc/assets/js/50.8ad7176f.js"><link rel="prefetch" href="/orange_doc/assets/js/6.43fcf2a3.js"><link rel="prefetch" href="/orange_doc/assets/js/7.569ec916.js"><link rel="prefetch" href="/orange_doc/assets/js/vendors~docsearch.9170ad82.js">
    <link rel="stylesheet" href="/orange_doc/assets/css/0.styles.4198b232.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/orange_doc/" class="home-link router-link-active"><img src="/orange_doc/images/logo.jpg" alt="Orange框架" class="logo"> <span class="site-name can-hide">Orange框架</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/orange_doc/" class="nav-link">
  首页
</a></div><div class="nav-item"><a href="/orange_doc/快速开始.html" class="nav-link">
  快速开始
</a></div><div class="nav-item"><a href="/orange_doc/about.html" class="nav-link">
  文档
</a></div><div class="nav-item"><a href="https://www.kancloud.cn/chase688/orange_framework" target="_blank" rel="noopener noreferrer" class="nav-link external">
  看云镜像
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://gitee.com/zhucheer/orange" target="_blank" rel="noopener noreferrer" class="nav-link external">
  源码
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/orange_doc/" class="nav-link">
  首页
</a></div><div class="nav-item"><a href="/orange_doc/快速开始.html" class="nav-link">
  快速开始
</a></div><div class="nav-item"><a href="/orange_doc/about.html" class="nav-link">
  文档
</a></div><div class="nav-item"><a href="https://www.kancloud.cn/chase688/orange_framework" target="_blank" rel="noopener noreferrer" class="nav-link external">
  看云镜像
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://gitee.com/zhucheer/orange" target="_blank" rel="noopener noreferrer" class="nav-link external">
  源码
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <ul class="sidebar-links"><li><a href="/orange_doc/快速开始.html" class="sidebar-link">快速开始</a></li><li><a href="/orange_doc/config/配置.html" class="sidebar-link">配置</a></li><li><a href="/orange_doc/log/日志.html" class="sidebar-link">日志</a></li><li><a href="/orange_doc/config/命令行参数.html" class="sidebar-link">命令行参数</a></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>请求与响应</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/orange_doc/route/路由.html" class="sidebar-link">路由</a></li><li><a href="/orange_doc/route/静态资源绑定.html" class="sidebar-link">静态资源绑定</a></li><li><a href="/orange_doc/route/中间件.html" class="sidebar-link">中间件</a></li><li><a href="/orange_doc/controller/控制器.html" class="sidebar-link">控制器</a></li><li><a href="/orange_doc/request/Session.html" class="sidebar-link">Session</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>数据库</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/orange_doc/DB/Mysq操作.html" class="sidebar-link">Mysq操作</a></li><li><a href="/orange_doc/DB/Redis操作.html" class="sidebar-link">Redis操作</a></li></ul></section></li><li><a href="/orange_doc/view.html" class="sidebar-link">视图</a></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>其他</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/orange_doc/base/项目目录.html" class="sidebar-link">项目目录</a></li><li><a href="/orange_doc/base/项目编译.html" class="sidebar-link">项目编译</a></li><li><a href="/orange_doc/base/优雅退出.html" class="sidebar-link">优雅退出</a></li><li><a href="/orange_doc/base/平滑重启.html" class="sidebar-link">平滑重启</a></li><li><a href="/orange_doc/base/pprof支持.html" class="active sidebar-link">pprof支持</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/orange_doc/base/pprof支持.html#pprof-支持" class="sidebar-link">pprof 支持</a></li></ul></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>实用工具</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/orange_doc/tools/图片验证码.html" class="sidebar-link">图片验证码</a></li><li><a href="/orange_doc/tools/简单队列.html" class="sidebar-link">简单队列</a></li><li><a href="/orange_doc/tools/消息队列.html" class="sidebar-link">消息队列</a></li><li><a href="/orange_doc/tools/http请求客户端.html" class="sidebar-link">http请求客户端</a></li><li><a href="/orange_doc/tools/文件上传.html" class="sidebar-link">文件上传</a></li><li><a href="/orange_doc/tools/发送邮件.html" class="sidebar-link">发送邮件</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h2 id="pprof-支持"><a href="#pprof-支持" class="header-anchor">#</a> pprof 支持</h2> <p>在 golang 官方包中有一个 pprof 包专门用来做性能分析；
该工具能方便的对我们的程序进行 内存，goroutine，cpu 进行分析；
使用该包时会有几个 http 接口暴露出来；
为了接入方便，Orange 框架已经进行了封装，通过配置文件即可开启或关闭性能分析接口。</p> <h3 id="快速使用"><a href="#快速使用" class="header-anchor">#</a> 快速使用</h3> <p>通过该配置可以进行配置性能分析接口的开启与关闭；</p> <div class="language- extra-class"><pre class="language-text"><code>[app]
  ...
    pprofOpen = true
</code></pre></div><p>功能开启后，我们启动项目，可以通过访问 <a href="http://127.0.0.1:8088/debug/pprof/" target="_blank" rel="noopener noreferrer">http://127.0.0.1:8088/debug/pprof/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> 来查看性能分析页面；
通过 go tool 工具还能将相关的性能指标生成 svg 查看；</p> <h3 id="分析接口"><a href="#分析接口" class="header-anchor">#</a> 分析接口</h3> <p>CPU 分析：http://127.0.0.1.1:8088/debug/pprof/profile
Goroutine 阻塞事件：http://127.0.0.1.1:8088/debug/pprof/block
活跃的 Goroutine：http://127.0.0.1.1:8088/debug/pprof/goroutine
堆内存分类分析：http://127.0.0.1.1:8088/debug/pprof/heap
互斥锁分析：http://127.0.0.1.1:8088/debug/pprof/mutex
系统线程分析：http://127.0.0.1.1:8088/debug/pprof/threadcreate</p> <h3 id="生成-svg"><a href="#生成-svg" class="header-anchor">#</a> 生成 svg</h3> <p>通过如下命令可以将 cpu 分析结果保持到一个 svg 文件中</p> <div class="language- extra-class"><pre class="language-text"><code>go tool pprof -svg -output ./cpu.svg http://127.0.0.1.1:8088/debug/pprof/profile
</code></pre></div><p>说明：默认情况下 cup 分析会监控30s内的 cpu 使用情况，还可以通过在接口后面添加参数来配置时间，如果分析 60s 如下：</p> <div class="language- extra-class"><pre class="language-text"><code>go tool pprof -svg -output ./cpu.svg http://127.0.0.1.1:8088/debug/pprof/profile?seconds=60
</code></pre></div><p>另外，也可以将相应的分析结果源文件保存到本地后进行svg生成，以实现自动化程序调用等功能。
例如，我们将 http://127.0.0.1.1:8088/debug/pprof/profile 地址请求到的文件保存到本地 ./profile 文件，然后我们可以通过如下命令来转换成 svg 格式</p> <div class="language- extra-class"><pre class="language-text"><code>go tool pprof -svg -output ./profile .svg ./profile 
</code></pre></div></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/orange_doc/base/平滑重启.html" class="prev">
        平滑重启
      </a></span> <span class="next"><a href="/orange_doc/tools/图片验证码.html">
        图片验证码
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/orange_doc/assets/js/app.e323b7be.js" defer></script><script src="/orange_doc/assets/js/2.8ffd84cf.js" defer></script><script src="/orange_doc/assets/js/1.d3b0779f.js" defer></script><script src="/orange_doc/assets/js/30.30aeda31.js" defer></script>
  </body>
</html>
